import 'package:flutter/material.dart';
import 'package:wechat/pages/discover/discover_detail_page.dart';

class DiscoverCell extends StatefulWidget {
  final String imageName;
  final String title;
  final String subTitle;
  final String subImageName;

  const DiscoverCell(
      {super.key,
      required this.imageName,
      required this.title,
      this.subTitle = '',
      this.subImageName = ''});

  @override
  State<StatefulWidget> createState() {
    return _DiscoverCellState();
  }
}

class _DiscoverCellState extends State<DiscoverCell> {
  Color _selectedColor = Colors.white;

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () { //跳转
        Navigator.of(context).push(
          MaterialPageRoute(builder: (BuildContext ctx) {
            //print(ctx); //Builder(dirty)
            return DiscoverDetailPage(widget.title);
          }),
        );
        setState(() {
          _selectedColor = Colors.white;
        });
      },
      onTapDown: (TapDownDetails details) {
        setState(() {
          _selectedColor = Colors.grey;
        });
      },
      onTapCancel: () {
        print("取消点击");
        setState(() {
          _selectedColor = Colors.white;
        });
      },
      child: Container(
        color: _selectedColor,
        height: 44,
        padding: EdgeInsets.only(left: 15, right: 10),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Container(
              child: Row(
                children: [
                  Image(
                    image: AssetImage(widget.imageName),
                    width: 20,
                    height: 20,
                    fit: BoxFit.fill,
                  ),
                  SizedBox(
                    width: 15,
                  ),
                  Text(widget.title),
                ],
              ),
            ),
            Container(
              child: Row(
                children: [
                  widget.subTitle.length > 0
                      ? Text(
                          widget.subTitle,
                          style: TextStyle(color: Colors.grey),
                        )
                      : Container(),
                  SizedBox(
                    width: 8,
                  ),
                  widget.subImageName.length > 0
                      ? Image(
                          image: AssetImage(widget.subImageName),
                          width: 15,
                          height: 15,
                          fit: BoxFit.fill,
                        )
                      : Container(),
                  Icon(Icons.keyboard_arrow_right),
                ],
              ),
            )
          ],
        ),
      ),
    );
  }
}
